////////////////////////////////////////////////////////////////////////////
//
//  Crytek Engine Source File.
//  Copyright (C), Crytek Studios, 2001-2011.
// -------------------------------------------------------------------------
//  File name:   FlowReverbManager.cpp
//  Version:     v1.00
//  Created:     Jan 18th 2011 by Sergiy Shaykin
//  Compilers:   Visual Studio.NET 2008
//  Description: 
// -------------------------------------------------------------------------
//  History:
//
////////////////////////////////////////////////////////////////////////////

#include "StdAfx.h"
#include <ISound.h>
#include <IReverbManager.h>
#include "FlowBaseNode.h"



class CFlowNode_ReverbManagerPause : public CFlowBaseNode<eNCT_Instanced>
{

public:
	CFlowNode_ReverbManagerPause( SActivationInfo * pActInfo ) 
	{
		m_bPause = false;
	}

	~CFlowNode_ReverbManagerPause()
	{
	}

	IFlowNodePtr Clone( SActivationInfo * pActInfo )
	{
		return new CFlowNode_ReverbManagerPause(pActInfo);
	}

	enum INPUTS 
	{
		eIn_Enable,
		eIn_Disable,
	};

	enum OUTPUTS 
	{
	};

	VIRTUAL void GetConfiguration(SFlowNodeConfig& config)
	{
		static const SInputPortConfig inputs[] = 
		{
			InputPortConfig_Void		("Pause", _HELP("Pause Reverb Manager")),
			InputPortConfig_Void		("Continue", _HELP("Continue Reverb Manager")),
			InputPortConfig_Null()
		};
		static const SOutputPortConfig outputs[] = 
		{
			OutputPortConfig_Null()
		};    
		config.pInputPorts = inputs;
		config.pOutputPorts = outputs;
		config.sDescription = _HELP("Toggle Reverb Manager Pause");
		config.SetCategory(EFLN_APPROVED);
	}


	void Pause(bool bPause)
	{
		ISoundSystem* pSoundSystem = gEnv->pSoundSystem;
		if(!pSoundSystem || !pSoundSystem->GetIReverbManager())
			return;

		pSoundSystem->GetIReverbManager()->TogglePause(bPause);

		m_bPause = bPause;
	}


	VIRTUAL void Serialize(SActivationInfo* pActInfo, TSerialize ser)
	{
		bool bOldPause = m_bPause;
		ser.BeginGroup("ReverbManager");
		ser.Value( "pause", m_bPause );
		ser.EndGroup();
			
		if (ser.IsReading())
		{
			if(m_bPause != bOldPause)
				Pause( m_bPause );
		}
	}


	VIRTUAL void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
	{
		switch (event)
		{
		case eFE_Initialize:
			{
				if(gEnv->IsEditor() && !gEnv->IsEditing())
				{
					if(m_bPause)
						Pause(false);
				}
			}
			break;
		case eFE_Activate:
			{
				if (IsPortActive(pActInfo, eIn_Enable))
				{
					Pause(true);
				}

				if (IsPortActive(pActInfo, eIn_Disable))
				{
					Pause(false);
				}
			}
			break;
		}
	}

	VIRTUAL void GetMemoryUsage(ICrySizer * s) const
	{
		s->Add(*this);
	}

protected:
	static bool m_bPause;
};

bool CFlowNode_ReverbManagerPause::m_bPause = false;

REGISTER_FLOW_NODE("Sound:ReverbManagerPause", CFlowNode_ReverbManagerPause);
